//index.js
//获取应用实例
const app = getApp()

Page({
  data: {
    imgUrls: [],
    isMsg:true,
    msgNum:'99+',
    nav_newHot_item:[],
    noticeList: [],
    classBig:[],
    goodsItem: [],
  },
  //初始化
  onLoad: function (options) {
    var that=this;
    if(this.__data__.msgNum == 0){
      this.setData({
        isMsg:false
        })
    }
    wx.request({
      url: 'http://127.0.0.1:8080/indexContent',
      data: {},
      header: {
        'content-type': 'application/json'
      },
      success: function (res) {
        that.setData({
          noticeList: res.data.list,
          nav_newHot_item: res.data.navNewhotItemList, 
          imgUrls: res.data.indexImgUrlsList,
          classBig: res.data.classBigList
        })
      }
    })
    wx.request({
      url: 'http://127.0.0.1:8080/queryComponentGoods',
      data: { viewId: 'index' },
      header: {
        'content-type': 'application/json'
      },
      success: function (res) {
        console.log(res);
        that.setData({
          goodsItem: res.data.componentGoodsList
        })
      }
    })
  },
  mettingPlace:function(){
    wx.redirectTo({
      url: '../mettingPlace/mettingPlace',
    })
  },
  msgNum:function(){
    wx.redirectTo({
      url: '../mssage/mssage?viewId=message'
    })
  },
  classDetail:function(e){
    var id = e.currentTarget.dataset.id;
    if((id == 0)||(id == 2)||(id == 3)){
      var viewId='';
      if(id==0){
        viewId = 'classDetailsHot'
      }else if(id==2){
        viewId = 'classDetailsDiscount';
      }else if(id == 3){
        viewId = 'classDetailsNew';
      }
      wx.redirectTo({
        url: '../classDetail/classDetail?viewId=' + viewId,
      })
    }else{
      var viewId='';
      if (id == 1) {
        viewId = 'classDetailSkin'
      } else if (id == 4) {
        viewId = 'classDetailFoods';
      }
      wx.redirectTo({
        url: '../mssage/mssage?viewId=' + viewId,
      })
    }
  },
  handleEventListener:function(e){
    console.log('e')
  },
  /* 这里实现控制中间凸显图片的样式 */
  handleChange: function (e) {
    this.setData({
      currentIndex: e.detail.current
    })
  },
})
